/*
 * Copyright 2018-9-30 20:11:44 The JA-SIG Collaborative. All rights reserved.
 * distributed with thi file and available online at
 */
package com.lap.scp.erp.ao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;

import com.lap.scd.commons.ao.AbstractAO;
import com.lap.scd.commons.constant.RespCode;
import com.lap.scd.commons.page.Page;
import com.lap.scd.commons.page.PageResult;
import com.lap.scd.commons.page.PageUtils;
import com.lap.scd.commons.result.Resp;
import com.lap.scp.erp.ao.SuppilerAO;
import com.lap.scp.erp.core.SuppilerManager;
import com.lap.scp.erp.domain.SuppilerDO;
import com.lap.scp.erp.query.SuppilerQueryVO;

/**
 * <pre>
 *   默认 供应商信息，记录供应商信息，供应商的描述，加入时间等应用实现类，提供供应商信息，记录供应商信息，供应商的描述，加入时间等相关的流程应用操作、查询等。
 *
 * </pre>
 * 
 * @author 劳水生 Exp
 * @Date 2018-9-30 20:11:44
 * @since 2.0.0
 */
@Service("suppilerAO")
public class DefaultSuppilerAO extends AbstractAO implements SuppilerAO {
	/**
	 * 供应商信息，记录供应商信息，供应商的描述，加入时间等业务操作对象
	 */
	@Resource
	private SuppilerManager suppilerManager;

	@Override
	public Resp<SuppilerDO> insertSuppiler(SuppilerDO suppilerDO, BindingResult errors) {
		Resp<SuppilerDO> resp = new Resp<>();
		try {
			super.validate(resp, errors, suppilerDO);
			if (resp.isSuccess()) {
				suppilerManager.insertSuppiler(suppilerDO);
				resp.setData(suppilerDO);
			}
		} catch (Exception e) {
			resp.putMsg(RespCode.Error, super.getMsg("505", new String[] { e.getLocalizedMessage() }));
			super.writeLog(suppilerDO, e);
		}
		return resp;
	}

	@Override
	public Resp<Integer> deleteById(Integer suppilerId) {
		Resp<Integer> resp = new Resp<>();
		try {
			int flag = suppilerManager.deleteById(suppilerId);
			resp.setData(flag);
		} catch (Exception e) {
			resp.putMsg(RespCode.Error, super.getMsg("505", new String[] { e.getLocalizedMessage() }));
			super.writeLog(suppilerId, e);
		}
		return resp;
	}

	@Override
	public Resp<SuppilerDO> queryById(Integer suppilerId) {
		Resp<SuppilerDO> model = new Resp<>();
		try {
			SuppilerDO suppilerDO = suppilerManager.queryById(suppilerId);
			model.setData(suppilerDO);
		} catch (Exception e) {
			model.putMsg(RespCode.Error, super.getMsg("505", new String[] { e.getLocalizedMessage() }));
			super.writeLog(suppilerId, e);
		}
		return model;
	}

	@Override
	public PageResult<SuppilerDO> queryPage(Page page, SuppilerQueryVO queryVO) {
		PageResult<SuppilerDO> pr = new PageResult<>();
		try {
			List<SuppilerDO> list = suppilerManager.queryPage(page, queryVO);

			PageUtils.copyPage(pr, page);
			pr.setData(list);
		} catch (Exception e) {
			pr.putMsg(RespCode.Error, super.getMsg("505", new String[] { e.getLocalizedMessage() }));
			super.writeLog(new Object[] { page, queryVO }, e);
		}
		return pr;
	}

	@Override
	public Resp<Integer> updateSuppiler(SuppilerDO suppilerDO, BindingResult errors) {
		Resp<Integer> resp = new Resp<>();
		try {
			super.validate(resp, errors, suppilerDO);
			if (resp.isSuccess()) {
				int flag = suppilerManager.updateSuppiler(suppilerDO);
				resp.setData(flag);
			}
		} catch (Exception e) {
			resp.putMsg(RespCode.Error, super.getMsg("505", new String[] { e.getLocalizedMessage() }));
			super.writeLog(suppilerDO, e);
		}
		return resp;
	}

	@Override
	public Resp<List<SuppilerDO>> queryList() {
		Resp<List<SuppilerDO>> resp = new Resp<>();
		try {
			List<SuppilerDO> list = suppilerManager.queryList();
			resp.setData(list);
		} catch (Exception e) {
			super.writeLog(e);
		}
		return resp;
	}

}
